import time

import requests

from config.config import *

import os
if os.environ["ENV"] == "pord":
    PORJECT_ADDRESS = "http://192.168.10.171:8080/job/jkzdh_git_erp/allure/"
elif os.environ["ENV"] == "test":
    PORJECT_ADDRESS = "http://192.168.10.171:8080/job/jkzdh_git_erp_test/allure/"

def send_feishu_message(webhook):
    message_data = [
        [
            {
                "tag": "text",
                "text": f"项目名称：{PROJECT}"
            }
        ],
        [
            {
                "tag":"text",
                "text":f"执行时间：{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}"
            }
        ],
        [
            {
                "tag":"text",
                "text":"详细消息:"
            },
            {
                "tag": "a",
                "text": "查看测试报告",
                "href": PORJECT_ADDRESS
            }
        ]
    ]
    payload = {
        "msg_type": "post",
        "content": {
            "post": {
                "zh_cn": {
                    "title": "自动化测试报告",
                    "content": message_data
                }
            }
        }
    }
    if FEISHU_IS_SEND:
        response = requests.post(webhook, json=payload)
